package gwt.seca.client.agents;

import gwt.seca.client.SoundManager;

import javax.vecmath.Vector3f;

import com.allen_sauer.gwt.voices.client.Sound;

public class Ernest10Anim extends AbstractAnim {

	final static int ANIM_MOVE = 1;
	final static int ANIM_BUMP = 2;
	final static int ANIM_TURN_LEFT = 3;
	final static int ANIM_TURN_RIGHT = 4;
//	final static int ANIM_TOUCH_FORWARD = 5;
//	final static int ANIM_TOUCH_LEFT = 6;
//	final static int ANIM_TOUCH_RIGHT = 7;
	
	public Ernest10Anim(Ernest10Model model) {
		super(model);
		mModel = model;
	}
	
	protected void startImpl(Vector3f trans, Vector3f rot) {
		float dist = trans.length();
		float rotZ = rot.getZ();
		switch (mAnimID) {
		case ANIM_MOVE:
			mNumberOfCycles = 0;
			mExtremeBodyTrans.set(dist, 0, 0);
			mExtremeBodyRot.set(0, 0, 0);
			mExtremePectoralFinsRot.set(0, 0, 0);
			mExtremePelvicFinsRot.set(0, 0, 0);
			mExtremeCaudalFinRot.set(0, 0, 0);
			mExtremeDorsalFinRot.set(0, -10, 0);
			break;
		case ANIM_BUMP:
			mNumberOfCycles = 1;
			mExtremeBodyTrans.set(0.2f, 0, 0);
			mExtremeBodyRot.set(0, 20, 0);
			mExtremePectoralFinsRot.set(0, 0, 0);
			mExtremePelvicFinsRot.set(0, 0, 0);
			mExtremeCaudalFinRot.set(0, 20, 0);
			mExtremeDorsalFinRot.set(0, 0, 0);
			mSound = mModel.mSoundBump;
			mSoundStart = 0;
			break;
		case ANIM_TURN_LEFT:
			mNumberOfCycles = 0;
			mExtremeBodyTrans.set(0, 0, 0);
			mExtremeBodyRot.set(0, 0, rotZ);
			mExtremePectoralFinsRot.set(0, 0, 0);
			mExtremePelvicFinsRot.set(0, 0, 0);
			mExtremeCaudalFinRot.set(0, 0, -30);
			mExtremeDorsalFinRot.set(0, 0, 0);
			break;
		case ANIM_TURN_RIGHT:
			mNumberOfCycles = 0;
			mExtremeBodyTrans.set(0, 0, 0);
			mExtremeBodyRot.set(0, 0, rotZ);
			mExtremePectoralFinsRot.set(0, 0, 0);
			mExtremePelvicFinsRot.set(0, 0, 0);
			mExtremeCaudalFinRot.set(0, 0, 30);
			mExtremeDorsalFinRot.set(0, 0, 0);
			break;
		default:
			mAnimID = 0;
			mModel = null;
		}
	}
	public void updateImpl(float scale, float scale2) {
//		mModel.mBodyTrans.scale(scale, mExtremeBodyTrans);
//		mModel.mBodyRot.scale(scale, mExtremeBodyRot);
		mModel.mPosition.set(mStartPosition);
		mModel.mRotation.set(mStartRotation);
		Vector3f trans = new Vector3f(mExtremeBodyTrans);
		trans.scale(scale);
		mModel.mPosition.set(mModel.localToParentRef(trans));
		mModel.mRotation.scaleAdd(scale, mExtremeBodyRot, mStartRotation);
		mModel.mPectoralFinsRot.scale(scale, mExtremePectoralFinsRot);
		mModel.mPelvicFinsRot.scale(scale, mExtremePelvicFinsRot);
		mModel.mCaudalFinRot.scale(scale, mExtremeCaudalFinRot);
		mModel.mDorsalFinRot.scale(scale, mExtremeDorsalFinRot);
	}
	public void stopImpl() {
//		mModel.mBodyTrans.set(0, 0, 0);
//		mModel.mBodyRot.set(0, 0, 0);
		mModel.mPectoralFinsRot.set(0, 0, 0);
		mModel.mPelvicFinsRot.set(0, 0, 0);
		mModel.mCaudalFinRot.set(0, 0, 0);
		mModel.mDorsalFinRot.set(0, 0, 0);
	}
	
	protected Ernest10Model mModel;
	private Vector3f mExtremeBodyTrans = new Vector3f();
	private Vector3f mExtremeBodyRot = new Vector3f();
	private Vector3f mExtremePectoralFinsRot = new Vector3f(); //Rotation of the left fin. Rotation of the right fin is the opposite on the axis X and Z
	private Vector3f mExtremePelvicFinsRot = new Vector3f(); //Rotation of the left fin. Rotation of the right fin is the opposite
	private Vector3f mExtremeCaudalFinRot = new Vector3f();
	private Vector3f mExtremeDorsalFinRot = new Vector3f();
	
	
}
